package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.service.YkService;
import com.mysql.cj.xdevapi.JsonArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.crypto.Data;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@RestController
public class YkController {

    @Autowired
    private YkService ykService;

    @RequestMapping("/s1")
    public JSONObject select1(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONArray data = new JSONArray();
        result.put("data",data);

        List<Map<String , Object>>maps = ykService.select1();

        JSONObject col1 = new JSONObject();
        col1.put("name","运输次数");
        col1.put("value","68");
        data.add(col1);

        JSONObject col2 = new JSONObject();
        col2.put("name","运输里程");
        col2.put("value","128909");
        data.add(col2);

        JSONObject col3 = new JSONObject();
        col3.put("name","运输时长");
        col3.put("value","126694000");
        data.add(col3);


        return result;
    }

    @RequestMapping("/s2")
    public JSONObject select2() {
        JSONObject result = new JSONObject();
        result.put("status", 0);
        result.put("msg", "");
        JSONArray data = new JSONArray();
        result.put("data", data);

        return result;
    }

    @RequestMapping("/s3")
    public JSONObject select3() {
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject data = new JSONObject();
        result.put("data",data);
        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);
        JSONObject col1 = new JSONObject();
        col1.put("name","序号");
        col1.put("id","id");

        columns.add(col1);

        JSONObject col2 = new JSONObject();
        col2.put("name","序号");
        col2.put("id","name");

        columns.add(col2);

        JSONObject col3 = new JSONObject();
        col3.put("name","序号");
        col3.put("id","cta");

        columns.add(col3);

        JSONObject col4 = new JSONObject();
        col4.put("name","序号");
        col4.put("id","ctb");

        columns.add(col4);

        JSONObject col5 = new JSONObject();
        col5.put("name","序号");
        col5.put("id","ctc");

        columns.add(col5);

        List<Map<String ,Object>> maps=ykService.select3();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("id",map.get("id"));
            row.put("name",map.get("name"));
            row.put("cta",map.get("cta"));
            row.put("ctb",map.get("ctb"));
            row.put("ctc",map.get("ctc"));
            rows.add(row);
        }

        return result;
    }
    @RequestMapping("/s4")
    public JSONObject select4() {
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject data = new JSONObject();
        result.put("data",data);
        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);
        JSONObject col1 = new JSONObject();
        col1.put("name","序号");
        col1.put("id","id");

        columns.add(col1);

        JSONObject col2 = new JSONObject();
        col2.put("name","序号");
        col2.put("id","name");

        columns.add(col2);

        JSONObject col3 = new JSONObject();
        col3.put("name","序号");
        col3.put("id","cta");

        columns.add(col3);

        JSONObject col4 = new JSONObject();
        col4.put("name","序号");
        col4.put("id","ctb");

        columns.add(col4);

        JSONObject col5 = new JSONObject();
        col5.put("name","序号");
        col5.put("id","ctc");

        columns.add(col5);

        List<Map<String ,Object>> maps=ykService.select4();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("id",map.get("id"));
            row.put("name",map.get("name"));
            row.put("cta",map.get("cta"));
            row.put("ctb",map.get("ctb"));
            row.put("ctc",map.get("ctc"));
            rows.add(row);
        }

        return result;
    }
}
